package bairui.international.console.web.controller.authority.authorization.department;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.lianjing.sh.project.authority.model.domain.jpa.TB_Authority;
import com.lianjing.sh.project.authority.model.domain.jpa.TB_RoleBase;
import com.lianjing.sh.project.authority.service.Service_Authority;
import com.lianjing.sh.project.authority.web.config.Config_ProjectAuthority_Authority;
import com.lianjing.sh.project.authority.web.controller.authority.tool.Util_Authority;
import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.module.context.ModuleContext;
import com.lianjing.sh.spring.web.controller.enhance.navigations.context.NavigationContext;


/**
 * @generated
 *
 * C_Authority_Authorization_Department_Authority_ActionShow
 *
 */
@Controller
public class C_Authority_Authorization_Department_Authority_ActionShow
 extends SC_Authority_Authorization_Department_Authority_ActionShow 
{

	@Autowired @Lazy private Service_Authority service_Authority;
	@Autowired private Config_ProjectAuthority_Authority config_Security_Authority;
	
	/**
	 * 显示权限Action
	 */
	@Action(ActionShow.class)
	@GetMapping(ActionShow.RequestMappingValue)
	public ModelAndView actionShow(
		ModelMap map, HttpServletRequest request,
		NavigationContext navigationContext, ModuleContext moduleContext, 
		@PathVariable(name=ActionShow.PathVariableName.DepartmentId) long departmentId,
		@RequestParam String groupName_moduleName,
		@RequestParam String submitActionUrl,
		@RequestParam boolean isSelected
	) throws Exception {
		/*
		 * 获取选中的action
		 */
		List<TB_Authority> ownered = this.service_Authority.list(
				it->it.roleBases.contains(new TB_RoleBase(departmentId))
					.and(it.abandonFlag.eq(false))
			);
		if(isSelected){
			map.put(
					"actions", 
					Util_Authority.outputSelectedActions(groupName_moduleName, ownered, config_Security_Authority)
				);
		}else{
			map.put(
					"actions", 
					Util_Authority.outputUnselectedActions(groupName_moduleName, ownered, config_Security_Authority)
				);
		}
		// 模块
		map.put(
				"module", 
				Util_Authority.getModule(groupName_moduleName, config_Security_Authority)
			);
		//
		map.put("submitActionUrl", submitActionUrl);
		return new ModelAndView("admin/authority/common/actionShow");
	}

}


